package cn.ml.lambda;

import cn.ml.entity.Student;

import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class LambdaDemo3 {
    public static void main(String[] args) {
        Random random = new Random();
        //测试数据，请不要纠结数据的严谨性
        List<Student> studentList = Student.getStudentList();

        Student.printStudents(studentList);
        System.out.println("---------移除一个后-------------------");
        int index2 = random.nextInt(studentList.size());
        studentList.remove(index2);

        //从对象列表中提取某列
        List<String> nameList = studentList.stream().map(Student::getName).collect(Collectors.toList());
        System.out.println(nameList);
        for (String name:nameList){
            System.out.println(name);
        }
        System.out.println("-----------------------------------");
        nameList.forEach(s-> System.out.println(s));


        //从对象列表中提取age并去重
        List<Integer> ageList = studentList.stream().map(Student::getAge).distinct().collect(Collectors.toList());
        ageList.forEach(a-> System.out.println(a));


    }

}
